﻿using KalevaAalto.DataPart.Enums;
using KalevaAalto.DataPart.Models;
using OfficeOpenXml.Style;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KalevaAalto.DataPart.Excel.Epplus
{
    internal class EpplusStyle : IStyle
    {
        private ExcelStyle _style;
        public EpplusStyle(ExcelStyle style) { _style = style; }
        public bool WrapText { get => _style.WrapText; set => _style.WrapText=value; }

        private readonly static IDictionary<HorizontalAlignment, ExcelHorizontalAlignment> s_horizontalAlignments = new Dictionary<HorizontalAlignment, ExcelHorizontalAlignment>
        {
            {HorizontalAlignment.Left,ExcelHorizontalAlignment.Left },
            {HorizontalAlignment.Center,ExcelHorizontalAlignment.Center},
            {HorizontalAlignment.Right,ExcelHorizontalAlignment.Right },
        }.ToImmutableDictionary();
        public HorizontalAlignment HorizontalAlignment { get => s_horizontalAlignments.First(it=>it.Value==_style.HorizontalAlignment).Key; set => _style.HorizontalAlignment = s_horizontalAlignments[value]; }

        private readonly static IDictionary<VerticalAlignment, ExcelVerticalAlignment> s_verticalAlignments = new Dictionary<VerticalAlignment, ExcelVerticalAlignment>
        {
            {VerticalAlignment.Top,ExcelVerticalAlignment.Top },
            {VerticalAlignment.Center,ExcelVerticalAlignment.Center},
            {VerticalAlignment.Bottom , ExcelVerticalAlignment.Bottom },
        }.ToImmutableDictionary();
        public VerticalAlignment VerticalAlignment { get => s_verticalAlignments.First(it => it.Value == _style.VerticalAlignment).Key; set => _style.VerticalAlignment = s_verticalAlignments[value]; }

        public IFont Font => new EpplusFont(_style.Font);

        public string NumberFormat { get =>_style.Numberformat.Format; set => _style.Numberformat.Format=value; }

        public IBorder Border => new EpplusBorder(_style);

        public IFill Fill => new EpplusFill(_style.Fill);
    }
}
